
package com.ptu.spzx.controller;


import com.github.pagehelper.PageInfo;
import com.ptu.spzx.domain.Delete.DeleteIds;
import com.ptu.spzx.domain.Knowledge.KnowledgePoint;
import com.ptu.spzx.model.vo.common.Result;
import com.ptu.spzx.model.vo.common.ResultCodeEnum;
import com.ptu.spzx.service.IKnowledgePointService;
import io.swagger.v3.oas.models.security.SecurityScheme;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author YT
 * @since 2024-01-28
 */
@RestController
@RequestMapping("/sc/exam/knowledgePoint")
@AllArgsConstructor
public class KnowledgePointController {

    private  final IKnowledgePointService iKnowledgePointService;

    /**
     * 新增知识点
     * @param knowledgePoint
     * @return
     */
    @PostMapping("/insertPoint")
    @PreAuthorize("@permissionService.hasPermission('exam:knowledgePoint:insertPoint')")
    public Result addKnowledgePoint(@RequestBody KnowledgePoint knowledgePoint){
        iKnowledgePointService.addKnowledgePoint(knowledgePoint);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    /**
     * 更新知识点
     * @param knowledgePoint
     * @return
     */
    @PutMapping("/updatePoint")
    @PreAuthorize("@permissionService.hasPermission('exam:knowledgePoint:updatePoint')")
    public Result updateKnowledgePoint(@RequestBody KnowledgePoint knowledgePoint){
        iKnowledgePointService.updateKnowledgePoint(knowledgePoint);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    /**
     * 批量删除知识点
     * @param
     * @return
     */
    @DeleteMapping("/deleteBatchPoint")
    @PreAuthorize("@permissionService.hasPermission('exam:knowledgePoint:deleteBatchPoint')")
    public Result deleteKnowledgePointByIds(@RequestBody DeleteIds deleteIds){
        iKnowledgePointService.deleteKnowledgePointByIds(deleteIds);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    /**
     * 查询单条知识点
     * @param id
     * @return
     */
    @GetMapping("/getPoint/{id}")
    @PreAuthorize("@permissionService.hasPermission('exam:knowledgePoint:getPoint')")
    public Result<KnowledgePoint> QueryKnowledgePointById(@PathVariable("id") Long id){
        KnowledgePoint knowledgePoint=iKnowledgePointService.QueryKnowledgePoint(id);
        return Result.build(knowledgePoint, ResultCodeEnum.SUCCESS);
    }

    /**
     * 根据课程批量查询知识点
     * @param BelongCourseId
     * @return
     */
    @GetMapping("/getBatchPoint/{BelongCourseId}/{pageNum}/{pageSize}")
    @PreAuthorize("@permissionService.hasPermission('exam:knowledgePoint:getBatchPoint')")
    public Result QueryKnowledgePointByBelongCourseIds(@PathVariable(required = true) Long BelongCourseId,
                                                                                     @PathVariable("pageNum") Integer pageNum,
                                                                                     @PathVariable("pageSize")  Integer pageSize,
                                                                                      @RequestParam("keyWord") String keyWord){
        PageInfo<KnowledgePoint> pageInfo=iKnowledgePointService.QueryKnowledgePointByBelongCourseIds(BelongCourseId,pageNum,pageSize, keyWord);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }

    //知识点的使用排序
    @GetMapping("/orderByKnowledgeUsed/{pageNum}/{pageSize}")
    @PreAuthorize("@permissionService.hasPermission('exam:knowledgePoint:orderByKnowledgeUsed')")
    public Result orderByKnowledgeUsed(@PathVariable("pageSize") Integer pageSize,
                                       @PathVariable("pageNum") Integer pageNum){
        PageInfo<KnowledgePoint> pageInfo=iKnowledgePointService.orderByKnowledgeUsed(pageSize,pageNum);
        return Result.build(pageInfo,ResultCodeEnum.SUCCESS);
    }
}



